/*
 * config_app.h
 *
 *  Created on: Jul 20, 2020
 *      Author: liwei
 */

#ifndef EXAMPLES_WG_WG_MAIN_CONFIG_APP_H_
#define EXAMPLES_WG_WG_MAIN_CONFIG_APP_H_

#include "can_svc.h"
#include "device_app.h"
#include "eth_svc.h"
#include "freertos/semphr.h"
#include "ingwaycomm.h"
#include "iot_svc.h"
#include "modbus_svc.h"
#include "nvs.h"
#include "nvs_flash.h"
#include "tcp_log.h"
#include "uart_svc.h"
#include "wifi_svc.h"

SemaphoreHandle_t ModbusTCP_handle_sem; // 因为用的全局变量 static ModbusRtuDataTPDF *mModbusRtuDataRec; saveConfig()以此全局变量获取动作条件;
                                        // 导致前一步Modbus写操作在写NVS区还未结束时，后续接收的帧填充到相应的位置，成为继续写NVS的条件依据；故加此互斥锁
SemaphoreHandle_t http_sem;
typedef enum { ///< 所有分区边数据地址
    PARTITION_TABLE_ADDR_NULL = 0,
    PARTITION_TABLE_ADDR_MODBUS1_COM_ADDR,
    PARTITION_TABLE_ADDR_MODBUS1_BAUDRATE_HADDR,
    PARTITION_TABLE_ADDR_MODBUS1_BAUDRATE_LADDR,
    PARTITION_TABLE_ADDR_MODBUS1_WORDSIZE_ADDR,
    PARTITION_TABLE_ADDR_MODBUS1_PARITY_ADDR,
    PARTITION_TABLE_ADDR_MODBUS1_STOPBITS_ADDR,
    PARTITION_TABLE_ADDR_MODBUS1_COMMPROTOCOL_ADDR,
    PARTITION_TABLE_ADDR_MODBUS1_JOINTPORT_ADDR,
    PARTITION_TABLE_ADDR_MODBUS1_TIMEOUT_Addr,
    PARTITION_TABLE_ADDR_MODBUS1_RETAINDATA1_ADDR,
    PARTITION_TABLE_ADDR_MODBUS1_RETAINDATA2_ADDR,
    PARTITION_TABLE_ADDR_MODBUS1_RETAINDATA3_ADDR,
    PARTITION_TABLE_ADDR_MODBUS1_RETAINDATA4_ADDR,
    PARTITION_TABLE_ADDR_MODBUS2_COM_ADDR,
    PARTITION_TABLE_ADDR_MODBUS2_BAUDRATE_HADDR,
    PARTITION_TABLE_ADDR_MODBUS2_BAUDRATE_LADDR,
    PARTITION_TABLE_ADDR_MODBUS2_WORDSIZE_ADDR,
    PARTITION_TABLE_ADDR_MODBUS2_PARITY_ADDR,
    PARTITION_TABLE_ADDR_MODBUS2_STOPBITS_ADDR,
    PARTITION_TABLE_ADDR_MODBUS2_COMMPROTOCOL_ADDR,
    PARTITION_TABLE_ADDR_MODBUS2_JOINTPORT_Addr,
    PARTITION_TABLE_ADDR_MODBUS2_TIMEOUT_Addr,
    PARTITION_TABLE_ADDR_MODBUS2_RETAINDATA1_ADDR,
    PARTITION_TABLE_ADDR_MODBUS2_RETAINDATA2_ADDR,
    PARTITION_TABLE_ADDR_MODBUS2_RETAINDATA3_ADDR,
    PARTITION_TABLE_ADDR_MODBUS2_RETAINDATA4_ADDR,
    PARTITION_TABLE_ADDR_CAN_BAUDRATE_HADDR,
    PARTITION_TABLE_ADDR_CAN_BAUDRATE_LADDR,
    PARTITION_TABLE_ADDR_CAN_RETAINDATA1_ADDR,
    PARTITION_TABLE_ADDR_CAN_RETAINDATA2_ADDR,
    PARTITION_TABLE_ADDR_CAN_RETAINDATA3_ADDR,
    PARTITION_TABLE_ADDR_CAN_RETAINDATA4_ADDR,
    PARTITION_TABLE_ADDR_EHERNET_IP_HADDR,
    PARTITION_TABLE_ADDR_EHERNET_IP_LADDR,
    PARTITION_TABLE_ADDR_EHERNET_GATEWAY_HADDR,
    PARTITION_TABLE_ADDR_EHERNET_GATEWAY_LADDR,
    PARTITION_TABLE_ADDR_EHERNET_SUBMASK_HADDR,
    PARTITION_TABLE_ADDR_EHERNET_SUBMASK_LADDR,
    PARTITION_TABLE_ADDR_EHERNET_DNS_HADDR,
    PARTITION_TABLE_ADDR_EHERNET_DNS_LADDR,
    PARTITION_TABLE_ADDR_EHERNET_IPMODE_ADDR,
    PARTITION_TABLE_ADDR_EHERNET_ROLE_ADDR,
    PARTITION_TABLE_ADDR_EHERNET_DNSMODE_ADDR,
    PARTITION_TABLE_ADDR_EHERNET_PORT_ADDR,
    PARTITION_TABLE_ADDR_EHERNET_TIMEOUT_ADDR,
    PARTITION_TABLE_ADDR_EHERNET_RETAINDATA1_ADDR,
    PARTITION_TABLE_ADDR_EHERNET_RETAINDATA2_ADDR,
    PARTITION_TABLE_ADDR_EHERNET_RETAINDATA3_ADDR,
    PARTITION_TABLE_ADDR_EHERNET_RETAINDATA4_ADDR,
    PARTITION_TABLE_ADDR_WIFI_MODE_ADDR,
    PARTITION_TABLE_ADDR_WIFI_STAIP_HADDR,
    PARTITION_TABLE_ADDR_WIFI_STAIP_LADDR,
    PARTITION_TABLE_ADDR_WIFI_STAGATEWAY_HADDR,
    PARTITION_TABLE_ADDR_WIFI_STAGATEWAY_LADDR,
    PARTITION_TABLE_ADDR_WIFI_STASUBMASK_HADDR,
    PARTITION_TABLE_ADDR_WIFI_STASUBMASK_LADDR,
    PARTITION_TABLE_ADDR_WIFI_STADNS_HADDR,
    PARTITION_TABLE_ADDR_WIFI_STADNS_LADDR,
    PARTITION_TABLE_ADDR_WIFI_STASSID1_ADDR,
    PARTITION_TABLE_ADDR_WIFI_STASSID2_ADDR,
    PARTITION_TABLE_ADDR_WIFI_STASSID3_ADDR,
    PARTITION_TABLE_ADDR_WIFI_STASSID4_ADDR,
    PARTITION_TABLE_ADDR_WIFI_STASSID5_ADDR,
    PARTITION_TABLE_ADDR_WIFI_STASSID6_ADDR,
    PARTITION_TABLE_ADDR_WIFI_STASSID7_ADDR,
    PARTITION_TABLE_ADDR_WIFI_STASSID8_ADDR,
    PARTITION_TABLE_ADDR_WIFI_STAPASSWD1_ADDR,
    PARTITION_TABLE_ADDR_WIFI_STAPASSWD2_ADDR,
    PARTITION_TABLE_ADDR_WIFI_STAPASSWD3_ADDR,
    PARTITION_TABLE_ADDR_WIFI_STAPASSWD4_ADDR,
    PARTITION_TABLE_ADDR_WIFI_STAPASSWD5_ADDR,
    PARTITION_TABLE_ADDR_WIFI_STAPASSWD6_ADDR,
    PARTITION_TABLE_ADDR_WIFI_STAPASSWD7_ADDR,
    PARTITION_TABLE_ADDR_WIFI_STAPASSWD8_ADDR,
    PARTITION_TABLE_ADDR_WIFI_STADHCPMODE_Addr,
    PARTITION_TABLE_ADDR_WIFI_STADNSMODE_Addr,
    PARTITION_TABLE_ADDR_WIFISTA_RETAINDATA1_ADDR,
    PARTITION_TABLE_ADDR_WIFISTA_RETAINDATA2_ADDR,
    PARTITION_TABLE_ADDR_WIFISTA_RETAINDATA3_ADDR,
    PARTITION_TABLE_ADDR_WIFISTA_RETAINDATA4_ADDR,
    PARTITION_TABLE_ADDR_WIFI_APIP_HADDR,
    PARTITION_TABLE_ADDR_WIFI_APIP_LADDR,
    PARTITION_TABLE_ADDR_WIFI_APSUBMASK_HADDR,
    PARTITION_TABLE_ADDR_WIFI_APSUBMASK_LADDR,
    PARTITION_TABLE_ADDR_WIFI_APSSID1_ADDR,
    PARTITION_TABLE_ADDR_WIFI_APSSID2_ADDR,
    PARTITION_TABLE_ADDR_WIFI_APSSID3_ADDR,
    PARTITION_TABLE_ADDR_WIFI_APSSID4_ADDR,
    PARTITION_TABLE_ADDR_WIFI_APSSID5_ADDR,
    PARTITION_TABLE_ADDR_WIFI_APSSID6_ADDR,
    PARTITION_TABLE_ADDR_WIFI_APSSID7_ADDR,
    PARTITION_TABLE_ADDR_WIFI_APSSID8_ADDR,
    PARTITION_TABLE_ADDR_WIFI_APPASSWD1_ADDR,
    PARTITION_TABLE_ADDR_WIFI_APPASSWD2_ADDR,
    PARTITION_TABLE_ADDR_WIFI_APPASSWD3_ADDR,
    PARTITION_TABLE_ADDR_WIFI_APPASSWD4_ADDR,
    PARTITION_TABLE_ADDR_WIFI_APPASSWD5_ADDR,
    PARTITION_TABLE_ADDR_WIFI_APPASSWD6_ADDR,
    PARTITION_TABLE_ADDR_WIFI_APPASSWD7_ADDR,
    PARTITION_TABLE_ADDR_WIFI_APPASSWD8_ADDR,
    PARTITION_TABLE_ADDR_WIFI_APSTARTIP_HADDR,
    PARTITION_TABLE_ADDR_WIFI_APSTARTIP_LADDR,
    PARTITION_TABLE_ADDR_WIFI_APENDIP_HADDR,
    PARTITION_TABLE_ADDR_WIFI_APENDIP_LADDR,
    PARTITION_TABLE_ADDR_WIFI_APDHCPMODE_Addr,
    PARTITION_TABLE_ADDR_WIFIAP_RETAINDATA1_ADDR,
    PARTITION_TABLE_ADDR_WIFIAP_RETAINDATA2_ADDR,
    PARTITION_TABLE_ADDR_WIFIAP_RETAINDATA3_ADDR,
    PARTITION_TABLE_ADDR_WIFIAP_RETAINDATA4_ADDR,
    PARTITION_TABLE_ADDR_IOT_TYPE_ADDR,
    PARTITION_TABLE_ADDR_IOT_RETAINDATA1_ADDR,
    PARTITION_TABLE_ADDR_IOT_RETAINDATA2_ADDR,
    PARTITION_TABLE_ADDR_IOT_RETAINDATA3_ADDR,
    PARTITION_TABLE_ADDR_IOT_RETAINDATA4_ADDR,
    PARTITION_TABLE_ADDR_SERVER1_RM1_ADDR,
    PARTITION_TABLE_ADDR_SERVER1_RM2_ADDR,
    PARTITION_TABLE_ADDR_SERVER1_RM3_ADDR,
    PARTITION_TABLE_ADDR_SERVER1_RM4_ADDR,
    PARTITION_TABLE_ADDR_SERVER1_RM5_ADDR,
    PARTITION_TABLE_ADDR_SERVER1_RM6_ADDR,
    PARTITION_TABLE_ADDR_SERVER1_RM7_ADDR,
    PARTITION_TABLE_ADDR_SERVER1_RM8_ADDR,
    PARTITION_TABLE_ADDR_SERVER1_RM9_ADDR,
    PARTITION_TABLE_ADDR_SERVER1_RM10_ADDR,
    PARTITION_TABLE_ADDR_SERVER1_RM11_ADDR,
    PARTITION_TABLE_ADDR_SERVER1_RM12_ADDR,
    PARTITION_TABLE_ADDR_SERVER1_RM13_ADDR,
    PARTITION_TABLE_ADDR_SERVER1_RM14_ADDR,
    PARTITION_TABLE_ADDR_SERVER1_RM15_ADDR,
    PARTITION_TABLE_ADDR_SERVER1_RM16_ADDR,
    PARTITION_TABLE_ADDR_SERVER1_PORT_ADDR,
    PARTITION_TABLE_ADDR_SERVER1_COMMSTYLE_ADDR,
    PARTITION_TABLE_ADDR_SERVER1_PROTOCOLTYPE_Addr,
    PARTITION_TABLE_ADDR_SERVER1_RETAINDATA1_ADDR,
    PARTITION_TABLE_ADDR_SERVER1_RETAINDATA2_ADDR,
    PARTITION_TABLE_ADDR_SERVER1_RETAINDATA3_ADDR,
    PARTITION_TABLE_ADDR_SERVER1_RETAINDATA4_ADDR,
    PARTITION_TABLE_ADDR_SERVER2_RM1_ADDR,
    PARTITION_TABLE_ADDR_SERVER2_RM2_ADDR,
    PARTITION_TABLE_ADDR_SERVER2_RM3_ADDR,
    PARTITION_TABLE_ADDR_SERVER2_RM4_ADDR,
    PARTITION_TABLE_ADDR_SERVER2_RM5_ADDR,
    PARTITION_TABLE_ADDR_SERVER2_RM6_ADDR,
    PARTITION_TABLE_ADDR_SERVER2_RM7_ADDR,
    PARTITION_TABLE_ADDR_SERVER2_RM8_ADDR,
    PARTITION_TABLE_ADDR_SERVER2_RM9_ADDR,
    PARTITION_TABLE_ADDR_SERVER2_RM10_ADDR,
    PARTITION_TABLE_ADDR_SERVER2_RM11_ADDR,
    PARTITION_TABLE_ADDR_SERVER2_RM12_ADDR,
    PARTITION_TABLE_ADDR_SERVER2_RM13_ADDR,
    PARTITION_TABLE_ADDR_SERVER2_RM14_ADDR,
    PARTITION_TABLE_ADDR_SERVER2_RM15_ADDR,
    PARTITION_TABLE_ADDR_SERVER2_RM16_ADDR,
    PARTITION_TABLE_ADDR_SERVER2_Port_ADDR,
    PARTITION_TABLE_ADDR_SERVER2_COMMSTYLE_ADDR,
    PARTITION_TABLE_ADDR_SERVER2_PROTOCOLTYPE_ADDR,
    PARTITION_TABLE_ADDR_SERVER2_RETAINDATA1_ADDR,
    PARTITION_TABLE_ADDR_SERVER2_RETAINDATA2_ADDR,
    PARTITION_TABLE_ADDR_SERVER2_RETAINDATA3_ADDR,
    PARTITION_TABLE_ADDR_SERVER2_RETAINDATA4_ADDR,
    PARTITION_TABLE_ADDR_SERVER3_RM1_ADDR,
    PARTITION_TABLE_ADDR_SERVER3_RM2_ADDR,
    PARTITION_TABLE_ADDR_SERVER3_RM3_ADDR,
    PARTITION_TABLE_ADDR_SERVER3_RM4_ADDR,
    PARTITION_TABLE_ADDR_SERVER3_RM5_ADDR,
    PARTITION_TABLE_ADDR_SERVER3_RM6_ADDR,
    PARTITION_TABLE_ADDR_SERVER3_RM7_ADDR,
    PARTITION_TABLE_ADDR_SERVER3_RM8_ADDR,
    PARTITION_TABLE_ADDR_SERVER3_RM9_ADDR,
    PARTITION_TABLE_ADDR_SERVER3_RM10_ADDR,
    PARTITION_TABLE_ADDR_SERVER3_RM11_ADDR,
    PARTITION_TABLE_ADDR_SERVER3_RM12_ADDR,
    PARTITION_TABLE_ADDR_SERVER3_RM13_ADDR,
    PARTITION_TABLE_ADDR_SERVER3_RM14_ADDR,
    PARTITION_TABLE_ADDR_SERVER3_RM15_ADDR,
    PARTITION_TABLE_ADDR_SERVER3_RM16_ADDR,
    PARTITION_TABLE_ADDR_SERVER3_PORT_ADDR,
    PARTITION_TABLE_ADDR_SERVER3_COMMSTYLE_ADDR,
    PARTITION_TABLE_ADDR_SERVER3_PROTOCOLTYPE_ADDR,
    PARTITION_TABLE_ADDR_SERVER3_RETAINDATA1_ADDR,
    PARTITION_TABLE_ADDR_SERVER3_RETAINDATA2_ADDR,
    PARTITION_TABLE_ADDR_SERVER3_RETAINDATA3_ADDR,
    PARTITION_TABLE_ADDR_SERVER3_RETAINDATA4_ADDR,
    PARTITION_TABLE_ADDR_GATEWAY_FUNCTIONCONF_HADDR,
    PARTITION_TABLE_ADDR_GATEWAY_FUNCTIONCONF_LADDR,
    PARTITION_TABLE_ADDR_GATEWAY_RESTOREDEFAULT_ADDR,
    PARTITION_TABLE_ADDR_GATEWAY_SYSTEMREBOOT_ADDR,
    PARTITION_TABLE_ADDR_GATEWAY_MODE_ADDR,
    PARTITION_TABLE_ADDR_GATEWAY_DEVINFOR_ADDR,
    // device information 0x00BD ~ 0x01FC
    PARTITION_TABLE_ADDR_GATEWAY_PRODUCT_TYPE = 0x01FD,
    PARTITION_TABLE_ADDR_GATEWAY_SUBVERSION,
    PARTITION_TABLE_ADDR_GATEWAY_SOFTWARE_VERSION,
    PARTITION_TABLE_ADDR_GATEWAY_SMART_CONFIG_ENABLE,

    PARTITION_TABLE_ADDR_GATEWAY_SERIESCODE1_ADDR = 0x8004, // CHINT device normal info
    PARTITION_TABLE_ADDR_GATEWAY_VERSIONID1_ADDR,
    PARTITION_TABLE_ADDR_GATEWAY_SYSTEMVERSION1_ADDR,
} PartitionTableAddrTPDF;

#define CONFIG_DEFAULT_VALUE_UART_BAUDRATE 19200
#define CONFIG_DEFAULT_VALUE_UART_TIMEOUT 400
#define CONFIG_DEFAULT_VALUE_CAN_BAUDRATE 9600
#define CONFIG_DEFAULT_VALUE_ETHERNET_IP 0x5008a8c0
#define CONFIG_DEFAULT_VALUE_ETHERNET_GATEWAY 0x0108a8c0
#define CONFIG_DEFAULT_VALUE_ETHERNET_SUBMASK 0x00ffffff
#define CONFIG_DEFAULT_VALUE_ETHERNET_DNS 0x0108a8c0
#define CONFIG_DEFAULT_VALUE_ETHERNET_PORT 502
#define CONFIG_DEFAULT_VALUE_ETHERNET_TIMEOUT 500
#define CONFIG_DEFAULT_VALUE_WIFI_STA_IP 0x5008a8c0
#define CONFIG_DEFAULT_VALUE_WIFI_STA_GATEWAY 0x0108a8c0
#define CONFIG_DEFAULT_VALUE_WIFI_STA_SUBMASK 0x00ffffff
#define CONFIG_DEFAULT_VALUE_WIFI_STA_DNS 0x0108a8c0
#define CONFIG_DEFAULT_VALUE_WIFI_PORT 502
#define CONFIG_DEFAULT_VALUE_WIFI_TIMEOUT 500
#define CONFIG_DEFAULT_VALUE_WIFI_AP_IP 0x0108a8c0
#define CONFIG_DEFAULT_VALUE_WIFI_AP_SUBMASK 0x00ffffff
#define CONFIG_DEFAULT_VALUE_WIFI_AP_IP_POOL_START 0x0208a8c0
#define CONFIG_DEFAULT_VALUE_WIFI_AP_IP_POOL_END 0x7f08a8c0
#define CONFIG_DEFAULT_VALUE_SERVER1_PORT 2345
#define CONFIG_DEFAULT_VALUE_SERVER2_PORT 2346
#define CONFIG_DEFAULT_VALUE_SERVER3_PORT 2347
#define CONFIG_DEFAULT_VALUE_SERVER_HEART_TIME 60
#define CONFIG_DEFAULT_VALUE_SERIES_CODE 0x0601
#define CONFIG_DEFAULT_VALUE_VER_ID 0x0001
#define CONFIG_DEFAULT_VALUE_VERSION 0x0101

#define ZHONGXIN_ACCOUNT 0x03D0 // 32B
#define ZHONGXIN_PWD 0x03E0 // 32B
#define ZHONGXIN_UNLOCK 0x03F0 // 16B
#define ZHONGXIN_SWITCH 0x03F8 // 16B
#define ZHONGXIN_CHECK 0x0400 // 16B

#define ZHONGXIN_ACC_LEN 32
#define ZHONGXIN_PWD_LEN 32

#define ZHONGXIN_REG_COUNT 16

/*
typedef enum {
    WIFI_MODE_NULL = 0,  //< null mode
    WIFI_MODE_STA,       //< WiFi station mode
    WIFI_MODE_AP,        //< WiFi soft-AP mode
    WIFI_MODE_APSTA,     //< WiFi station + soft-AP mode
    WIFI_MODE_MAX
} wifi_mode_t;
*/

typedef enum {
    PROTOCOL_TYPE_MODBUS_RTU = 1,
    PROTOCOL_TYPE_645 = 2,
    PROTOCOL_TYPE_698 = 3,
} ProtocolTypeTPDF;

typedef enum {
    JOINT_PORT_UP = 1,
    JOINT_PORT_DOWN = 2,
} JointPortTypeTPDF;

typedef enum {
    SERVER_COMM_TYPE_AUTO = 1,
    SERVER_COMM_TYPE_ETH = 2,
    SERVER_COMM_TYPE_WIFI = 3,
    SERVER_COMM_TYPE_IOT = 4,
} ServerCommTypeTPDF;

typedef enum {
    SERVER_PROTOCOL_TYPE_NONE = 0,
    SERVER_PROTOCOL_TYPE_HTTP = 1,
    SERVER_PROTOCOL_TYPE_HTTPS = 2,
    SERVER_PROTOCOL_TYPE_MQTT = 3,
    SERVER_PROTOCOL_TYPE_COAP = 4,
    SERVER_PROTOCOL_TYPE_MODBUS_RTU = 5,
} ServerProtocolTypeTPDF;

typedef enum {
    DEFAULT_COMMAND_COMM1 = 1,
    DEFAULT_COMMAND_COMM2 = 2,
    DEFAULT_COMMAND_CAN = 4,
    DEFAULT_COMMAND_EHTERNET = 8,
    DEFAULT_COMMAND_WIFI = 0x10,
    DEFAULT_COMMAND_IOT = 0x20,
    DEFAULT_COMMAND_ALL = 0x3f,
} DefaultCommandTPDF;

typedef enum {
    GATEWAY_MODE_PASSTHROUGH = 1,
    GATEWAY_MODE_TRANSMIT = 2,
} GatewayRunModeTPDF;

typedef struct
{
    UartConfigTPDF tUartConfig;
    uint16_t usProtocolType;
    uint16_t usJointPortType;
    uint16_t usTimeout;
    uint16_t usReserver[4];
} ComConfigTPDF;

typedef struct
{
    uint16_t cIP[16];
    uint16_t usPort;
    uint16_t usCommType;
    uint16_t usProtocolType;
    uint16_t usHeartTime;
    uint16_t usReserver[3];
} ServerConfigTPDF;

typedef struct
{
    uint16_t SeriesCode;
    uint16_t VerID;
    uint16_t Version;
    uint16_t SmartConfigEnable; // 0x200
    uint16_t up_period;
    uint16_t lkc_period;
    uint16_t lkc_year;
    uint16_t lkc_month;
    uint16_t lkc_day;
    uint16_t lkc_hour;
    uint16_t lkc_minute;
} ReserveConfigTPDF;

typedef struct
{
    uint16_t FactoryID;
    uint16_t ProductCategory;
    uint16_t ProductSeries;
    uint16_t ProductSubfamily;
    uint16_t RunState;
    uint16_t SoftwareVersion;
    uint16_t HardwareVersion;
    uint16_t ProductSN[12];
    uint16_t ProductDescription[12];
} BasicInforTPDF;

typedef struct
{
    uint16_t ModbusAddr;
    uint16_t AssetCode[8];
} GatewayInfoTPDF;

typedef struct
{
    char AssetCode[24];
} DeviceAssetCodeTPDF;

typedef struct
{
    uint16_t CommMode; // Community way:Auto ETH WIFI IOT
    uint16_t ProtocolType;
    uint16_t CommPort;
    uint16_t MQTTQos;
    uint16_t TransportMode; // Unknown, TCP, SSL, WS, WSS
    uint16_t LWTRetain;
    uint16_t LWTQos;
    uint16_t KeepaliveTime;
    uint16_t Reserve[8];
    uint16_t IPConfig[16];
    uint16_t ClientIDConfig[16];
    uint16_t UserNameConfig[16];
    uint16_t PasswordConfig[16];
    uint16_t LWTTopicConfig[8];
    uint16_t LWTMessageConfig[8];
    uint16_t SubscribeTopicConfig[32];
    uint16_t PublishTopicConfig[32];
} PlatformConfigTPDF;

typedef struct
{
    char zxAccount[32];
    char zxPWD[32];
    char zxUnlock[16];
    char zxSwitch[16];
    char zxCheck_status[16];
} Zhong_Xin_AccountTPDF;

typedef struct
{
    ComConfigTPDF tCom1Config;
    ComConfigTPDF tCom2Config;
    CanConfigTPDF tCanConfig;
    EthernetConfigTPDF tEthernetConfig;
    WifiConfigTPDF tWifiConfig;
    IotConfigTPDF tIotConfig;
    ServerConfigTPDF tServer1Config;
    ServerConfigTPDF tServer2Config;
    ServerConfigTPDF tServer3Config;
    volatile uint16_t usFunctionH;
    volatile uint16_t usFunctionL;
    uint16_t usDefaultCommand;
    uint16_t usRestart;
    uint16_t usGatewayRunMode;
    DeviceConfigTPDF tDeviceConfig[32];
    ReserveConfigTPDF ReserveConfig;
    BasicInforTPDF BasicInfor;
    GatewayInfoTPDF GatewayInfor;
    DeviceAssetCodeTPDF DeviceAssetCode[21];
    uint16_t Reserve[4];
    PlatformConfigTPDF PlatformConfig;

    Zhong_Xin_AccountTPDF ZhongXin;

} PartitionTableTPDF; ///< 分区表结构体

extern PartitionTableTPDF mPartitionTable;
extern DeviceConfigTPDF mDeviceConfigBak[CONFIG_DEVICE_MAXSURPPORT];

extern void CFG_vComm1_DefaultConfig(uint8_t ucWriteflash);
extern void CFG_vComm2_DefaultConfig(uint8_t ucWriteflash);
extern void CFG_vCan_DefaultConfig(uint8_t ucWriteflash);
extern void CFG_vEthernet_DefaultConfig(uint8_t ucWriteflash);
extern void CFG_vWifi_DefaultConfig(uint8_t ucWriteflash);
extern void CFG_vIot_DefaultConfig(uint8_t ucWriteflash);
extern void CFG_vServer1_DefaultConfig(uint8_t ucWriteflash);
extern void CFG_vServer2_DefaultConfig(uint8_t ucWriteflash);
extern void CFG_vServer3_DefaultConfig(uint8_t ucWriteflash);
extern void CFG_vDevice_DefaultConfig(uint8_t ucWriteflash);
extern void CFG_vReserve_DefaultConfig(uint8_t ucWriteflash);
extern void CFG_vBasicInfor_DefaultConfig(uint8_t ucWriteflash);
extern void CFG_vGatewayInfor_DefaultConfig(uint8_t ucWriteflash);
extern void CFG_vDeviceAssetCode_DefaultConfig(uint8_t ucWriteflash);
extern void CFG_vPlatform_DefaultConfig(uint8_t ucWriteflash);
extern void CFG_vDefaultConfig(void);
extern void CFG_vInit(void);
extern void CFG_vSaveConfig(uint16_t usIndex);
extern uint32_t CFG_dConvert_To_IP(uint16_t usIpH, uint16_t usIpL);
extern uint32_t CFG_dConvertString_To_IP(char* cChar);
extern void CFG_dConvert_To_Uint16(uint32_t uiIP, uint16_t* usIpH, uint16_t* usIpL);
extern char* CFG_dGet_Partition_Desc(uint16_t usIndex);
extern void CFG_dProcess_Protocol(ModbusRtuDataTPDF* tRec, ModbusRtuDataTPDF* tSend);
extern void ConvertUint16ToString(uint16_t* source, char* dest, int number);

void ResetConfig(void);
#endif /* EXAMPLES_WG_WG_MAIN_CONFIG_APP_H_ */
